// mock/index.js
import Mock from 'mockjs';

// 模拟登录接口
Mock.mock('http://localhost:8000/users/login', 'post', (options) => {
    const { username, password } = JSON.parse(options.body);

    // 检查用户名和密码
    if (username === '123' && password === '123456') {
        return {
            status: 200,
            message: 'Login successful',
            data: {
                token: 'fake-token',
                user: {
                    username: username,
                }
            }
        };
    } else {
        return {
            status: 400,
            message: 'Invalid username or password'
        };
    }
});
Mock.mock('http://localhost:8000/users/login', 'post', (options) => {
    const { username, password } = JSON.parse(options.body);

    // 检查用户名和密码
    if (username === '123' && password === '123456') {
        return {
            status: 200,
            message: 'Login successful',
            data: {
                access_token: 'fake-token',
                user: {
                    username: username,
                }
            }
        };
    } else {
        return {
            status: 400,
            message: 'Invalid username or password'
        };
    }
});
Mock.mock('http://localhost:8000/users/signUp', 'post', (options) => {
    const { username, password } = JSON.parse(options.body);
    return {
        status: 200,
        data: {
            username: username,
            password: password,
            message: 'SignUp successful'
        },
    };
});
Mock.mock('http://localhost:8000/users/signUp/sendVerificationCode', 'post', (options) => {
    const { email } = JSON.parse(options.body)
    return {
        status: 200,
        message: email + 'Verification code send',
    }
})

Mock.mock('http://localhost:8000/flights/geoCoordMap', 'get', {
    "北京": [116.407526, 39.904030],
    "上海": [121.473701, 31.230416],
    "广州": [113.264385, 23.129112],
    "深圳": [114.057868, 22.543099]
});

Mock.mock('http://localhost:8000/flights/routes', 'get', {
    "routes": [
        [{ "name": "北京", "time": '2024-7-20' }, { "name": "上海", "value": 2000000 }],
        [{ "name": "北京", "time": '2024-7-20' }, { "name": "广州", "value": 90 }],
        [{ "name": "北京", "time": '2024-7-21' }, { "name": "深圳", "value": 80 }],
        [{ "name": "上海", "time": '2024-7-21' }, { "name": "广州", "value": 70 }],
        [{ "name": "上海", "time": '2024-7-22' }, { "name": "深圳", "value": 60 }]
    ]
});

Mock.mock('http://localhost:8088/user/changePersonalInfo', 'post', (options) => {
    const {
        newUserId,
        newPassword,
        newEmail
    } = JSON.parse(options.body);

    // 假设这里处理了修改逻辑，这里简单地返回修改后的数据
    return {
        status: 200,
        data: {
            user: {
                userId: newUserId,
                email: newEmail,
                password: newPassword,
            },
            message: 'ChangePersonalInfo successful',
        },
    };
});

Mock.mock('http://localhost:8000/users/personal', 'post', (options) => {
    const { userId } = JSON.parse(options.body);
    return {
        //这里的userId和email是根据传回的userId在用户表数据库检索的结果
        status: 200,
        user: {
            userId: userId,
            password: '123456',
            email: '1234567890@gmail.com',
        },
    };
});


Mock.mock('http://localhost:8000/users/signUp/session_key', 'post', (options) => {
    return {
        //这里的userId和email是根据传回的userId在用户表数据库检索的结果
        status: 200,
        session_key: "fake_session_key",
    };
});

Mock.mock('http://localhost:8000/flights/map/form', 'post', (options) => {
    return {
        status: 200,
        data: [{
                "uid": "1",
                "airline": "阿斯塔纳航空",
                "price": 764,
                "duration": "5小时25分钟",
                "route": "PEK-ALA",
                "startDate": "7月13日",
                "airlineNum": "1234567",
                "airlineId": "01"
            },
            {
                "uid": "2",
                "airline": "南航",
                "price": 807,
                "duration": "5小时45分钟",
                "route": "PKX-ALA",
                "startDate": "7月13日",
                "airlineNum": "1234567",
                "airlineId": "01"
            },
            {
                "uid": "3",
                "airline": "南航",
                "price": 1000,
                "duration": "10小时20分钟",
                "route": "PKX-ALA",
                "startDate": "7月13日",
                "airlineNum": "1234567",
                "airlineId": "01"
            },

        ]

    }
})

Mock.mock('http://localhost:8000/users/collect/data', 'get', {
    data: [{
            uid: '1',
            airline: '阿斯塔纳航空',
            price: 764,
            duration: '5小时25分钟',
            route: 'PEK-ALA',
            startDate: '7月13日',
            airlineNum: '1234567',
            airlineId: '01'
        },
        {
            uid: '2',
            airline: '南航',
            price: 807,
            duration: '5小时45分钟',
            route: 'PKX-ALA',
            startDate: '7月13日',
            airlineNum: '1234567',
            airlineId: '01'
        },
        {
            uid: '3',
            airline: '南航',
            price: 1000,
            duration: '10小时20分钟',
            route: 'PKX-ALA',
            startDate: '7月13日',
            airlineNum: '1234567',
            airlineId: '01'
        }
    ]
});


// 定义模拟数据
const mockData = Mock.mock({
    'dates|30': ['@date("EEE")'], // 随机生成 7 个日期
    'prices|30': ['@integer(80, 3000)'] // 随机生成 7 个价格
});
// 模拟接口
Mock.mock('http://localhost:8000/flights/details/predication', 'post', (options) => {
    console.log('Mock request:', options);
    return {
        code: 200,
        data: mockData
    };
});
Mock.mock('http://localhost:8000/users/collect/save', 'post', (options) => {
    const { uid, userId } = JSON.parse(options.body);
    return {
        status: 200,
        uid: uid,
        userId: userId,
    };
});
Mock.mock('http://localhost:8000/users/collect/delete', 'post', (options) => {
    return {
        status: 200,
    };
});
Mock.mock('http://localhost:8000/adminUsers/manageFlight/data', 'get', {
    data: [{
            uid: '1',
            airline: '阿斯塔纳航空',
            price: 764,
            duration: '5小时25分钟',
            route: 'PEK-ALA',
            startDate: '7月13日',
            airlineNum: '1234567',
            airlineId: '01'
        },
        {
            uid: '2',
            airline: '南航',
            price: 807,
            duration: '5小时45分钟',
            route: 'PKX-ALA',
            startDate: '7月13日',
            airlineNum: '1234567',
            airlineId: '01'
        },
        {
            uid: '3',
            airline: '南航',
            price: 1000,
            duration: '10小时20分钟',
            route: 'PKX-ALA',
            startDate: '7月13日',
            airlineNum: '1234567',
            airlineId: '01'
        },
    ]
});
//航线管理-删除
Mock.mock('http://localhost:8000/adminUsers/manageFlight/delete', 'post', (options) => {
    return {
        status: 200,
    };
});
//航线管理-保存
Mock.mock('http://localhost:8000/adminUsers/manageFlight/save', 'post', (options) => {
    return {
        status: 200,
    };
});
//航线管理-添加新航线
Mock.mock('http://localhost:8000/adminUsers/manageFlight/add', 'post', (options) => {
    return {
        status: 200,
    };
});

Mock.mock('http://localhost:8000/flights/searchAirLine', 'post', (options) => {
    return {
        status: 200,
        data: [{
            "uid": "1",
            "airline": "阿斯塔纳航空",
            "price": 764,
            "duration": "5小时25分钟",
            "route": "PEK-ALA",
            "startDate": "7月13日",
            "airlineNum": "1234567",
            "airlineId": "01"
        }, ]
    }
});
// 使用 MockJS 生成模拟数据
const mockData2 = Mock.mock({
    'data|5': [
        { 'value|100-2000': 1, 'name|+1': ['北京', '上海', '广州', '深圳', '天津'] }
    ]
});

// 生成模拟的饼图数据
Mock.mock('http://localhost:8000/flights/RouteProfile', 'get', () => {
    return {
        code: 200,
        data: mockData2
    };
});
// 生成模拟的最多的机型、航班总数
Mock.mock('http://localhost:8000/flights/popularData/Flights', 'get', () => {
    return {
        data: {
            popularAircraft: "a22212222",
            totalFlights: 150877
        }
    };
});
Mock.mock('http://localhost:8000/flights/popularData/Planes', 'get', () => {
    return {
        data: {
            popularAirplane: "北京",
            totalLines: 500
        }
    };
});
// 生成模拟的折线图数据
Mock.mock('http://localhost:8000/flights/lineChartData', 'get', () => {

    // 生成随机日期
    const dates = Mock.mock({
        'dates|5': ['@date("yyyy-MM-dd")']
    }).dates;

    // 生成每天的航线总量数据
    const totalCounts = Mock.mock({
        'counts|5': ['@integer(500, 1000)']
    }).counts;

    // 构造折线图数据
    const lineChartData = {
        dates,
        counts: totalCounts
    };

    return {
        code: 200,
        data: lineChartData
    };
});
Mock.mock('http://localhost:8000/adminUsers/data', 'get', {
    data: [{
            userId: '123',
            email: '123412341234@email.com'
        },
        {
            userId: '345',
            email: '6784522341234@email.com'
        },
        {
            userId: '666',
            email: '342754234@email.com'
        },
    ]
});
//用户管理-删除
Mock.mock('http://localhost:8000/adminUsers/delete', 'post', (options) => {
    return {
        status: 200,
    };
});
//用户管理-保存
Mock.mock('http://localhost:8000/adminUsers/save', 'post', (options) => {
    return {
        status: 200,
    };
});
//用户管理-添加新航线
Mock.mock('http://localhost:8000/adminUsers/add', 'post', (options) => {
    return {
        status: 200,
    };
});
Mock.mock('http://localhost:8000/adminUsers/model/new', 'get', () => {
    return {
        status: 200,
    };
});
